package test.marui.com.mytest.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.annotation.FloatRange;

/**
 * Created by MR on 2019/1/25.
 */
public class BlurUtil {

    public static Bitmap blur(Context context, Bitmap originalBitmap, float radius) {

        if (radius <= 0) {
            return originalBitmap;
        }

        if (context == null) {
            return FastUtil.blur(originalBitmap, (int) radius);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return GaussianBlur.blur(context, originalBitmap, radius);
        } else {
            return FastUtil.blur(originalBitmap, (int) radius);
        }
    }

    public static Bitmap blur(Context context, Bitmap originalBitmap, float radius, @FloatRange(from = 1) float scale) {
        if (radius < 0) {
            return originalBitmap;
        }

        if (scale <= 1){
            return blur(context, originalBitmap, radius);
        }

        if (context == null) {
            return FastUtil.blur(originalBitmap, (int) radius, scale);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return GaussianBlur.blur(context, originalBitmap, radius, scale);
        } else {
            return FastUtil.blur(originalBitmap, (int) radius, scale);
        }

    }

}
